import sqlite3
# 连接数据库
conn = sqlite3.connect('book.db')
# 创建游标
cursor = conn.cursor()
# 创建表
# sql='''create table if not exists sys_user(
#             id int(111) primary key,
#             name varchar(25)
#             age int(3)
#         )'''
# cursor.execute(sql)
# conn.commit()
# 插入数据
# insert_sql='insert into sys_user(id,name,age) values(?,?,?)'
# cursor.execute(insert_sql,(1,"root",18))
# cursor.execute(insert_sql,(2,"root",18))
# cursor.execute(insert_sql,(3,"root",18))
# cursor.execute(insert_sql,(4,"root",18))
# conn.commit()

#查询数据
# select_sql="select * from sys_user"
# cursor.execute(select_sql)
# for row in cursor:
#     print(row)

cursor.execute = "select * from sys_user"
# result = cursor.fetchone()
# result = cursor.fetchone(3)
# result = cursor.fetchall()
# print(result)

#修改数据
update_sql = "update sys_user set age = ? where id = ?"
cursor.execute(update_sql,("admin",1))
conn.commit()

#删除数据
delete_sql = "delete from sys_user name where id = ?"
cursor.execute(delete_sql,(4,))
conn.commit()

cursor.execute(select_sql)
for row in cursor:
    print(row)